package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseFlow;
import com.ruoyi.base.service.IBaseFlowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备工单Controller
 * 
 * @author yepanpan
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/base/flow")
public class BaseFlowController extends BaseController
{
    @Autowired
    private IBaseFlowService baseFlowService;

    /**
     * 查询设备工单列表
     */
    @GetMapping("/select")
    public TableDataInfo select(BaseFlow baseFlow)
    {
        startPage();
        List<BaseFlow> list = baseFlowService.selectBaseFlowList(baseFlow);
        return getDataTable(list);
    }

    /**
     * 查询设备工单列表
     */
    @PreAuthorize("@ss.hasPermi('base:flow:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseFlow baseFlow)
    {
        startPage();
        List<BaseFlow> list = baseFlowService.selectBaseFlowList(baseFlow);
        return getDataTable(list);
    }

    /**
     * 导出设备工单列表
     */
    @PreAuthorize("@ss.hasPermi('base:flow:export')")
    @Log(title = "设备工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseFlow baseFlow)
    {
        List<BaseFlow> list = baseFlowService.selectBaseFlowList(baseFlow);
        ExcelUtil<BaseFlow> util = new ExcelUtil<BaseFlow>(BaseFlow.class);
        util.exportExcel(response, list, "设备工单数据");
    }


    /**
     * 获取设备工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:flow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseFlowService.selectBaseFlowById(id));
    }

    /**
     * 新增设备工单
     */
    @PreAuthorize("@ss.hasPermi('base:flow:add')")
    @Log(title = "设备工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseFlow baseFlow)
    {
        return toAjax(baseFlowService.insertBaseFlow(baseFlow));
    }

    /**
     * 修改设备工单
     */
    @PreAuthorize("@ss.hasPermi('base:flow:edit')")
    @Log(title = "设备工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseFlow baseFlow)
    {
        baseFlow.setUpdateBy(getUsername());
        return toAjax(baseFlowService.updateBaseFlow(baseFlow));
    }

    /**
     * 删除设备工单
     */
    @PreAuthorize("@ss.hasPermi('base:flow:remove')")
    @Log(title = "设备工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseFlowService.deleteBaseFlowByIds(ids));
    }

    /**
     * 新增设备工单
     */
    @PreAuthorize("@ss.hasPermi('base:flow:check')")
    @Log(title = "审核工单", businessType = BusinessType.UPDATE)
    @PostMapping("check")
    public AjaxResult check(@RequestBody BaseFlow baseFlow)
    {
        return toAjax(baseFlowService.checkBaseFlow(baseFlow));
    }
}
